package com.dolphin.controller.api;

import com.dolphin.base.BaseController;
import com.dolphin.commons.DynamicDataSource;
import com.dolphin.commons.OptionCacheUtil;
import com.dolphin.commons.ResponseBean;
import com.dolphin.config.SwaggerProperties;
import com.dolphin.model.Word;
import com.dolphin.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class AboutController extends BaseController {

    @Value("${version}")
    private String version;
    @Autowired
    private SwaggerProperties swaggerProperties;
    @Autowired
    private WordService wordService;
    @Autowired
    private ArticleService articleService;
    @Autowired
    private CommentService commentService;
    @Autowired
    private TagService tagService;
    @Autowired
    private UserService userService;

    @GetMapping("/about")
    public ResponseBean index() {
        Map map = new HashMap();
        map.put("version", version);
        map.put("dataBase", DynamicDataSource.dataSourceType);
        map.put("javaVersion", System.getProperty("java.version"));
        map.put("osName", System.getProperty("os.name"));
        map.put("osArch", System.getProperty("os.arch"));
        map.put("swaggerEnable", swaggerProperties.getEnable() ? "是" : "否");

        Word wordRandom = wordService.getWordRandom(1);
        if (wordRandom != null) {
            map.put("userInfoDescribe", wordRandom.getText());
        }
        map.put("aboutGitee", OptionCacheUtil.getValue("about_gitee"));
        map.put("aboutGithup", OptionCacheUtil.getValue("about_githup"));
        map.put("aboutWeb", OptionCacheUtil.getValue("about_web"));
        map.put("aboutWebUrl", OptionCacheUtil.getValue("about_web_url"));
        map.put("aboutSummery", OptionCacheUtil.getValue("about_summery"));
        map.put("aboutSummeryUrl", OptionCacheUtil.getValue("about_summery_url"));
        map.put("aboutGratuity", OptionCacheUtil.getValue("about_gratuity"));
        map.put("shareImage", OptionCacheUtil.getValue("about_share_image"));
        map.put("aboutCodeUrl", OptionCacheUtil.getValue("about_code_url"));

        map.put("webName", OptionCacheUtil.getValue("WEB_NAME"));
        map.put("webLogo", OptionCacheUtil.getValue("WEB_LOGO"));
        map.put("webSite", OptionCacheUtil.getValue("WEB_SITE"));
        map.put("webTitle", OptionCacheUtil.getValue("WEB_TITLE"));
        map.put("webCopyRight", OptionCacheUtil.getValue("WEB_COPYRIGHT"));

        map.put("articleCount", articleService.getArticleCount());
        map.put("commentCount", commentService.getCommentCount());
        map.put("tagCount", tagService.getTagCount());
        map.put("userCount", userService.getUserCount());

        return ResponseBean.success(map);
    }
}
